package mapEditor.interactor;
	
import mapEditor.map.MapCanvas;
import mapEditor.obj.EllipseObject;
import mapEditor.utils.MapLocation;

import java.awt.Graphics2D;
import java.awt.image.ImageObserver;

import org.json.JSONException;

// ********************************************************************
// *** CLASS: EllipseMouseAdapter
// ********************************************************************
public class DrawEllipseInteractor extends Interactor
{ public String getMouseModeMnemonic() { return("Draw Ellipse"); }
  private EllipseObject ellipse; // !null when drawing
  private MapLocation p0;
  private MapLocation p1;

  // ******************************************************************
  // *** CONSTRUCTOR: EllipseMouseAdapter
  // ******************************************************************
  public DrawEllipseInteractor(MapCanvas mapCanvas)
  { super(mapCanvas,DRAW_ELLIPSE); }

  // ******************************************************************
  // *** METHOD: paintMouseEffect
  // ******************************************************************
  public void paintMouseEffect(Graphics2D g,ImageObserver imageObserver)
  { if(ellipse!=null) ellipse.paint(g,imageObserver); }

  // ******************************************************************
  // *** METHOD: mouseDragged
  // ******************************************************************
  // Invoked when a mouse button is pressed and then dragged.
  protected void mouseDragged()
  {	if(ellipse!=null)
	{ p1.setX(mouseCurrent.getX());
	  p1.setY(mouseCurrent.getY());
      xmapCanvas.repaint();
	}
  }

  // ******************************************************************
  // *** METHOD: mouseMoved
  // ******************************************************************
  // Invoked when the mouse has been moved (with no buttons down).
  protected void mouseMoved() {}

  // ******************************************************************
  // *** METHOD: mousePressed
  // ******************************************************************
  // Invoked when a mouse button has been pressed.
  protected void mouseLeftPressed(MapLocation p)
  { if(ellipse==null)
	{ p0=p; p1=p.copy();
	  try { ellipse=new EllipseObject(objectModel,p0,p1); }
	  catch(JSONException e) { e.printStackTrace(); }
	  xmapCanvas.repaint();
	}
  }
  protected void mouseRightPressed(MapLocation p) {}

  // ******************************************************************
  // *** METHOD: mouseReleased
  // ******************************************************************
  // Invoked when a mouse button has been released.
  protected void mouseLeftReleased(MapLocation p)
  { drawObjectDone(ellipse,"ELLIPSE");  
    ellipse=null; xmapCanvas.repaint();
  }
  protected void mouseRightReleased(MapLocation p) {}

}